<?php
/**
 * Created by PhpStorm.
 * User: work
 * Date: 18-8-11
 * Time: 下午7:04
 */

namespace PddWechat\Models\Admin\Service;


use Dai\Framework\Base\BaseSessionInfo;
use Dai\Framework\Library\RedisExt;

class GoodsList
{
    /**
     * @param $basePageInfo
     * @return array
     */
    public function execute($basePageInfo) {
        /** @var BaseSessionInfo $sessionData */
        $sessionData = $basePageInfo->sessionInfo;

        if( $sessionData->adminLevel !== 10) {
            header("/mall/index");
            exit;
        }

        $goodsIds = RedisExt::getInstance()->get("hot_goods_ids");
        $goodsIds = explode(",", $goodsIds);

        $output = [
            'total' => 0,
            'list' => [],
        ];

        foreach ($goodsIds as $goodsId) {
            $goodsInfoStr = RedisExt::getInstance()->get("hot_goods_detail_$goodsId");
            if( trim($goodsInfoStr) == "") {
                continue;
            }
            $goodsInfo = json_decode($goodsInfoStr, true);
            if( $goodsInfo['goodsId'] > 0) {
                $output['list'][] = $goodsInfo;
            }
        }

        $output['total'] = count($output['list']);

        return $output;
    }
}